home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C & C++ Multimedia Cyber Classroom
/
C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso
/
cpphtp2
/
code.jar
/
code
/
ch07
/
fig07_07.txt
< prev
next >
Wrap
Text File
|
1998-02-27
|
682b
|
30 lines
1 // Fig. 7.7: fig07_07.cpp
2 // Using the this pointer to refer to object members.
3 #include <iostream.h>
4
5 class Test {
6 public:
7 Test( int = 0 ); // default constructor
8 void print() const;
9 private:
10 int x;
11 };
12
13 Test::Test( int a ) { x = a; } // constructor
14
15 void Test::print() const // ( ) around *this required
16 {
17 cout << " x = " << x
18 << "\n this->x = " << this->x
19 << "\n(*this).x = " << ( *this ).x << endl;
20 }
21
22 int main()
23 {
24 Test testObject( 12 );
25
26 testObject.print();
27
28 return 0;
29 }